package com.qyhl.webtv.commonlib.item;

import android.view.View;
import android.widget.TextView;

import com.orhanobut.hawk.Hawk;
import com.qyhl.webtv.basiclib.utils.StringUtils;
import com.qyhl.webtv.commonlib.R;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.news.GlobalNewsBean;
import com.zhy.adapter.recyclerview.base.ItemViewDelegate;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.Map;

/**
 * Created by qyhl on 2018/4/20.
 * 圈子文字
 */

public class ItemCircleText implements ItemViewDelegate<GlobalNewsBean> {
    public ItemCircleText() {
    }

    @Override
    public int getItemViewLayoutId() {
        return R.layout.news_item_newslist_circle_text;
    }

    @Override
    public boolean isForViewType(GlobalNewsBean item, int position) {
        return "15".equals(item.getType()) && item.getNewsStyle() == 1;
    }

    @Override
    public void convert(ViewHolder holder, GlobalNewsBean bean, int position) {
        TextView title = holder.getView(R.id.title);
        title.setText(bean.getTitle());


        TextView topName = holder.getView(R.id.topic_name);
        if(StringUtils.isNotEmpty(bean.getOrigin())){
            topName.setVisibility(View.VISIBLE);
            topName.setText("#" + bean.getOrigin() + "#");
        }else{
            topName.setVisibility(View.GONE);
        }


        TextView nickName = holder.getView(R.id.nickName);
        if (StringUtils.isNotEmpty(bean.getCatalogId())) {
            nickName.setText(bean.getCatalogId());
        } else {
            nickName.setText("匿名");
        }

        TextView scan = holder.getView(R.id.scan);
        try {
            int minPlay = Integer.parseInt(CommonUtils.getInstance().getMinPlay());
            if (minPlay == 0) {
                scan.setVisibility(View.GONE);
            } else {
                //判断评论数是否大于最少浏览数
                if (StringUtils.isEmpty(bean.getScanNum() + "")) {
                    scan.setVisibility(View.GONE);
                } else if (bean.getScanNum() >=
                        minPlay) {
                    scan.setText(StringUtils.transformNum(bean.getScanNum() + "") + "阅");
                    scan.setVisibility(View.VISIBLE);
                } else {
                    scan.setVisibility(View.GONE);
                }
            }

        } catch (Exception e) {
            scan.setVisibility(View.GONE);
        }

    }
}
